package DVD;

import java.util.Scanner;

public class UserRentSys {
    DVD[] dvds = RentDao.dvds;
    Scanner sc = new Scanner(System.in);
    DVD dvd = new DVD();
     public void start(People people) {
         while (true) {
             System.out.println("1.查看DVD信息\t2.租赁\t3.充值\t4.查看自己的账户");
             switch (sc.nextInt()) {
                 case 1:
                     showDVD();
                     break;
                 case 2:
                     rentDVD(people);
                     break;
                 case 3:
                     recharge(people);
                     break;
                 case 4:
                     showSelf(people);
                     break;
                 default:
                     System.out.println("我不理解！");
                     start(people);
             }
         }
     }
     public void showDVD(){

         System.out.println("DVD名称"+"\tDVD编号"+"\tDVD租借状态");
         for (int i = 0; i <RentDao.dvdCount ; i++) {
             System.out.println(dvds[i].getName()+"\t"+dvds[i].getId()+"\t\t"+dvds[i].isBorrowStatus());
         }
     }

    public void rentDVD(People people){
        showDVD();
        System.out.println("请输入要租赁的DVD编号：");
        String id = sc.next();
        for (int i = 0; i <RentDao.dvdCount ; i++) {
            if (dvds[i].getId().equals(id) && dvds[i].isBorrowStatus() == false
                    && people.getBalance() - dvds[i].getMoney() >= 0) {
                dvds[i].setBorrowStatus(true);
                people.setBalance(people.getBalance() - dvd.getMoney());
                System.out.println("租赁成功");
            }else{
                System.out.println("租赁失败");
                break;
            }
        }
    }
    public void recharge(People people){
        System.out.println("请输入充值金额：");
        double money = sc.nextDouble();
        if(money<50){
            System.out.println("充值金额最低50快起");
        }else if(money>200){
            people.setVip(true);
            System.out.println("恭喜成为会员,实际到账"+money/0.8);
            people.setBalance(money*0.8+people.getBalance());
        }else{
            people.setBalance(people.getBalance()+money);
            System.out.println("充值成功");
        }
    }
    public void showSelf(People people){
        System.out.println("借了的DVD名称"+"\t账户余额"+"\tVIP状态"+"归还与否");
        System.out.println("\t\t"+people.getBalance()+"\t"+people.isVip()+"\t");


    }
}
//class test{
//    public static void main(String[] args) {
//        RentDao dao = new RentDao();
//
//        UserRentSys sys = new UserRentSys();
//        sys.start(dao.people[0]);
//    }
//
//}